package com.myosw.dao;

import java.sql.Timestamp;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.commons.lang3.time.DateUtils;

import com.myosw.entity.SearchlogShow;
import com.myosw.entity.VisitlogShow;
import com.myosw.jdbc.common.QueryHelper;
import com.myosw.pojo.Filterlog;
import com.myosw.pojo.Searchlog;
import com.myosw.pojo.Visitlog;




public class VisitlogDao 
{

	/**
	 * 
	 * @param params 
	 * @return
	 */
	public int[] save(Object[][]  params)
	{
		String sql = "INSERT INTO myosw_visitlog(url,time,title,ip) VALUES(?,?,?,?)";
		return QueryHelper.batch(sql , params);
	}
	
	public boolean save(Visitlog visitlog)
	{
		return visitlog.save()>0?true:false;
	}
	
	public List<VisitlogShow> getTop(int from,int to)
	{
		String sql = "SELECT url,title,COUNT(*) as count " +
				"FROM myosw_visitlog  visitlog" +
				" GROUP BY visitlog.url" +
				" ORDER BY count DESC " +
				"LIMIT ?,?;";
		return QueryHelper.query(VisitlogShow.class, sql,from,to );
	}
	
	
	public int getlogCount(String url) 
	{
		Visitlog bean = new Visitlog();
		String filter = " url = "+url;
		return bean.totalCount(filter );
	}
	
	public List<Filterlog> getlogList(int page,int size,String url) 
	{
		Visitlog bean = new Visitlog();
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("url", url);
		return (List<Filterlog>) bean.getlist(page,size,map);
	}
	
	
}
